package com.itmate.chenshiguang.contreolle;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itmate.chenshiguang.entity.FamilyEntity;
import com.itmate.chenshiguang.service.FamilyService;

/**
 * Servlet implementation class toselect
 */
@WebServlet("/toselect")
public class toselect extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public toselect() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String name=request.getParameter("name");
		FamilyService a = new FamilyService();
		List<FamilyEntity> familylist = new ArrayList<>();
		Map<Integer,String> familymap = new HashMap();
		familylist = a.selectAllFamily();
		for (FamilyEntity familyEntity : familylist) {
			familymap.put(familyEntity.getId(), familyEntity.getName());
			
		}
		List list = a.selectFamily(name);
		request.setAttribute("list", list);
		request.getRequestDispatcher("/WEB-INF/jsp/csg/index.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
